Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




update( ) FUNCTION


The 'update( )' Function updates the current Set by getting the values from the other Set.


Example :


x = {"Mohan", "Kriti", "Salim"}
y = {"Sia", "Andrew", "Kriti"}
x.update(y)
print(x) 


Output :



  {'Mohan', 'Sia', 'Kriti', 'Salim', 'Andrew'}

So, in the above code we have created a 'Set' and initialised to the variable 'x'.


x = {"Mohan", "Kriti", "Salim"}

java_Collections

Then what we have done is, put the names, 'Sia', 'Andrew' and 'Kriti' in another set 'y'.


y = {"Sia", "Andrew", "Kriti"}

java_Collections

And used the 'update( )' Function to add the new Set 'y'(With values 'Sia', 'Andrew' and 'Kriti') to the existing Set 'x'.


x.update(y)

And the new values, 'Sia' and 'Andrew' from Set 'y' gets added to the existing Set 'x'.


And since, 'Kriti' is present in both the Sets, 'Kriti' will be added once. Else it might cause a duplicate entry.


java_Collections

And we get the below output,


{'Mohan', 'Sia', 'Kriti', 'Salim', 'Andrew'}